package com.bos.service.impl;

import com.bos.data.model.AccessTokenModel;
import com.bos.data.model.BosUserModel;
import com.bos.data.repositories.jpa.UserJPARepository;
import com.bos.mapper.AccessTokenMapper;
import com.bos.service.AccessTokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;

@Service("accessTokenServiceImpl")
public class AccessTokenServiceImpl implements AccessTokenService {
    @Autowired
    AccessTokenMapper accMapper;
    @Autowired
    private UserJPARepository userJPARepository;
    @Transactional
    //1.如果过期的话，则将AccessTokenModel给插入到数据库·中去
    @Override
    public int insertAccessToken(AccessTokenModel as) {
        // TODO Auto-generated method stub
        return accMapper.insertAccessToken(as);
    }

    //2.查询出AccessTokenModel中的数据
    @Override
    public List<AccessTokenModel> findAccessToken(String type) {
        // TODO Auto-generated method stub
        return accMapper.findAccessToken(type);
    }

    //3.根据id去更新AccessTokenModel中的数据
    @Transactional
    @Override
    public int updateByExpirIn(AccessTokenModel acce) {
        // TODO Auto-generated method stub
        return accMapper.updateByExpirIn(acce);
    }

    //4.J将用户信息保存到用户表中去
    @Transactional
    @Override
    public void insertUsers(List<BosUserModel> user) {
        // TODO Auto-generated method stub
        userJPARepository.save(user);
    }

    //5.查询出用户表中的数据
    @Override
    public List<BosUserModel> findUsers() {
        return accMapper.findUsers();
    }

    //6.根据名字去获取用户表中的信息
    @Override
    public BosUserModel findUserByName(String name) {
        return accMapper.findUserByName(name);
    }

}
